<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>购物车</title>
	<?php
	include("connection.php");
	session_start();
	$sql = "select shopid from shopcar where userid = {$_SESSION['userid']}";
	$queryresult = mysqli_query($connection,$sql);
	$row = mysqli_fetch_assoc($queryresult);
	?>
    <style>
        body {
            margin: 0;
            font-family: Arial, sans-serif;
        }
		img {
			height: 200px;
		}
        header {
            background-color: #4CAF50;
            color: #FFF;
            padding: 20px;
            text-align: center;
        }
        h1 {
            margin: 0;
            font-size: 36px;
            font-weight: normal;
        }
        main {
            padding: 20px;
            max-width: 800px;
            margin: 0 auto;
        }
		a {
			background-color: #F1EFC7;
			color: #000000;
			padding: 10px;
			text-decoration: none;
			font-size: 16px;
			box-shadow: #666 0px 0px 6px;
			text-align: center;
			border: medium;
		}
        .product {
            display: flex;
            margin-bottom: 20px;
            border: 1px solid #CCC;
            padding: 10px;
            border-radius: 5px;
            box-shadow: 0 0 5px rgba(0,0,0,0.2);
        }
        .product img {
            width: 200px;
            margin-right: 20px;
        }
        .product h2 {
            margin: 0;
            font-size: 24px;
        }
        .product p {
            margin: 0 0 10px 0;
            font-size: 18px;
        }
        .product .price {
            font-size: 24px;
            font-weight: bold;
            color: #F00;
        }
        footer {
            background-color: #EEE;
            padding: 20px;
            text-align: center;
        }
    </style>
</head>
	
<body>
	    <header> 
        <h1>购物车&nbsp;</h1>
    </header>
    <main>
        <div class="product">
            <div>
				<?php
				session_start();
	if($row == 0) {
		echo "<h1>购物车中暂无商品，快去选购吧！</h1>";
	}
	else {
		$sum_money = 0;
			foreach ($queryresult as $row){	
					echo '<img src="'.$row['shopid'].'.jpg'.'"></img>';					
					$sql_name = "select * from shop where shopid={$row['shopid']}";
					$result = mysqli_query($connection,$sql_name);
					$row_name = mysqli_fetch_assoc($result);
					$sum_money += $row_name['shopprice'];
					echo '<h2>'.$row_name['shopname'].'</h2>';
					echo '<p class="price">'.'￥'.$row_name['shopprice'].'</p><br>';
			}
					echo '<h1>总金额:'.$sum_money.'</h1><br>';
					echo '<a href="shopcar_buy.php">'.'下单'.'</a><br>';
		}
				?>
            </div>
        </div>
    </main>
    <footer>
        &copy; 2023 商品销售页面
    </footer>
</body>
			
</html>
